﻿using DotNetCore.CAP;
using MediatR;
using Project.API.Application.IntegrationEvents;
using Project.Domain.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace Project.API.Application.DomainEventHandlers
{
    public class ProjectCreatedEventHandler
        : INotificationHandler<ProjectCreatedEvent>
    {
        private readonly ICapPublisher _capPublisher;
        public ProjectCreatedEventHandler(ICapPublisher capPublisher)
        {
            _capPublisher = capPublisher;
        }
        public async Task Handle(ProjectCreatedEvent notification, CancellationToken cancellationToken)
        {
            var @event = new ProjectCreatedIntegrationEvent() { Introduction = notification.Project.Introduction, Name = notification.Project.Name };
            await _capPublisher.PublishAsync("finbook.project.create", @event);
        }
    }
}
